#ifndef APP_BTN_H
#define APP_BTN_H

#include "main.h"

typedef enum {
    APP_BTN_ENTER,
    APP_BTN_A,    
    APP_BTN_B,
    APP_BTN_MAX,
} app_btn_t;

typedef enum {
    APP_SINGLE_CLICK    = 1 << 0,
    APP_DOUBLE_CLICK    = 1 << 1,
    APP_MULTIPLE_CLICK  = 1 << 2,
    APP_LONG_CLICK      = 1 << 3,
    APP_LONG_CLICK_RELEASE = 1 << 4, 
} app_btn_state_t;

typedef enum {
    BTN_EFFECTIVE_LOW,
    BTN_EFFECTIVE_HIGH
} app_btn_effective_t;

typedef enum {
    MENU_UNLOCK             = 0,
    MENU_FEED               = 1,
    MENU_RESET              = 2,
    MENU_DC_LOCK            = 3,
    MENU_BAT_LOCK_STANDBY   = 4,
    MENU_BAT_LOCK           = 5,
    MENU_TIP                = 6,
    MENU_STANDBY            = 7
} app_menu_state_t;

typedef struct {
    app_menu_state_t    state;
    unsigned int        last;
} app_menu_t;


typedef void (*click_cb) (app_btn_t, app_btn_state_t);

#define MENU_TIMEOUT 30 * 1000
extern app_menu_t sg_menu;

void app_btn_effective_set(app_btn_t btn, app_btn_effective_t effective);
void app_btn_single_click_cb_register(app_btn_t btn, click_cb cb);
void app_btn_double_click_cb_register(app_btn_t btn, click_cb cb, unsigned int timeout);
void app_btn_multiple_click_cb_register(app_btn_t btn, click_cb cb, unsigned int timeout, unsigned char multiple);
void app_btn_other_multiple_click_cb_register(app_btn_t btn, click_cb cb, unsigned int timeout, unsigned char multiple);
void app_btn_factory_cb_register(click_cb cb);
void app_btn_long_click_cb_register(app_btn_t btn, click_cb cb, unsigned int timeout);
void app_btn_init(void);
void app_btn_task(void);

void app_dev_enter_btn_feed_cb_handler(app_btn_t btn, app_btn_state_t state);
void app_dev_enter_btn_resetwifi_cb_handler(app_btn_t btn, app_btn_state_t state);
void app_dev_btn_rotate_cb_handler(app_btn_t btn, app_btn_state_t state);



void app_menu_Init(void);
void app_menu_task(void);

void app_set_Clockwise(void);
void app_set_Counterclockwise(void);

void app_set_menu_led(app_menu_state_t state);

unsigned char app_get_menu_state(void);


void app_dev_btn_esc_burn_cb_handler(app_btn_t btn, app_btn_state_t state);
void app_dev_btn_enter_burn_cb_handler(app_btn_t btn, app_btn_state_t state);

unsigned char app_get_enter_capacity(void);

#endif